-- connWifi.lua connect the AP
ap_name = "wangdachui"
ap_passwd = "a150284289a"

function wifiStatus(x)
    if wifi.sta.status()==5 then
        print("Wifi connect OK")
        print("time_now="..tmr.now())
        return 0
    end
    n = x+1
    if n<100 then
        tmr.alarm(0, 200, 0,function() wifiStatus(n) end)
    end
end

if wifi.sta.status()<5 then
    print("Info: System connect Wifi...")
    wifi.setmode(wifi.STATION)
    wifi.sta.config(ap_name, ap_passwd)
    wifi.sta.autoconnect(1)
    print("time_now="..tmr.now())
    wifiStatus(0)
end

